<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Model_contact extends CI_Model{
    /**
     * Initialize table and primary field variable
     */
    var $table          = "tbl_contact";
    var $primary        = "id";
    
    /**
	* Constructor - Sets up the object properties.
	*/
    public function __construct(){
        parent::__construct();
    }
    
    /*
     * 141119
     * get all data
     */
    function get_all($limit = 1, $offset = 0){
        return $this->db->get($this->table, $limit, $offset);
    }
    function get_contact($limit = 1){
        $q = $this->db->query("
            SELECT * FROM `".$this->table."` AS A 
            LEFT JOIN master_state AS B 
            ON B.state_id = A.provinsi 
            LEFT JOIN master_city AS C 
            ON C.city_id = A.kota 
            LIMIT 1");
        
        if( $q->num_rows() > 0 ) return $q->row();
    }
    function save($isi){
        if($this->db->insert($this->table,$isi)) return true;
        else return false;
    }
    
    function delete($id){
        if($this->db->delete($this->table, array($this->primary => $id))) return true;
        else return false; 
    }
    
    function update($id,$array){
        $this->db->where($this->primary,$id);	
        if($this->db->update($this->table,$array)) return TRUE;
        else return FALSE;
    }
    function update_all($array){
        if($this->db->update($this->table,$array)) return TRUE;
        else return FALSE;
    }
    
    function select_by_id($id,$mod="result"){
        $q = $this->db->query("SELECT * FROM `".$this->table."` WHERE `".$this->primary."` = '".$id."'");
        if(strtolower($mod) == "result") return $q->result();
        else return $q->num_rows();
    }
}
/* End of file model_event.php */
/* Location: ./application/models/model_event.php */
